package me.zhengjie.modules.power.service.impl;

import me.zhengjie.modules.power.service.SysUserService;
import me.zhengjie.modules.power.service.dto.SysUser;
import me.zhengjie.modules.power.service.dto.SysUsersJobs;
import me.zhengjie.modules.power.service.dto.SysUsersRoles;
import me.zhengjie.modules.power.service.mapstruct.SysUsersJobsMapper;
import me.zhengjie.modules.power.service.mapstruct.SysUserMapper;
import me.zhengjie.modules.power.service.mapstruct.SysUsersRolesMapper;
import me.zhengjie.modules.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * SysUserServiceImpl
 *
 * @author weiruitao
 * @date 2021/11/17
 */
@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    SysUserMapper sysUserMapper;

    @Autowired
    UserService userService;

    @Autowired
    SysUsersJobsMapper sysUserJobsMapper;

    @Autowired
    SysUsersRolesMapper sysUserRolesMapper;

    @Override
    public int register(SysUser sysUser) {
        return sysUserMapper.insert(sysUser);
    }

    @Override
    public int addJobs(int userid){
       return sysUserJobsMapper.insert(new SysUsersJobs(userid,8));
    }

    @Override
    public int addRoles(int userid) {
        return sysUserRolesMapper.insert(new SysUsersRoles(userid,2));
    }

    @Override
    public int getUserId(String username) {
        return Integer.parseInt(sysUserMapper.getUserId(username));
    }

    @Override
    public int existName(String username) {
        String userId = sysUserMapper.getUserId(username);
        return userId == null ? 1 : 0;
    }
}
